package org.smart4j.framework.dwtest;

import org.smart4j.framework.util.StreamUtil;

import java.io.*;

/**
 * Created by
 *
 * @author dw
 * @date 2018/01/24
 */
public class MyStreamUtil {
    public static void main(String[] args) {
        InputStreamReader in = null;
        try {
            in = new InputStreamReader(new FileInputStream(new File("D:\\科信局指标自动运算开始.txt")), "UTF-8");


            String a = readStrByStream(in);
            System.out.println(a);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != in) {
                try {
                    in.close();
                    System.out.println("确保关闭文件流");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static String readStrByStream(InputStreamReader inputStreamReader) {
        StringBuilder sb = new StringBuilder();

        try {
            BufferedReader bread = new BufferedReader(inputStreamReader);
            String line;
            while ((line = (bread.readLine())) != null) {
                sb.append(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
}
